package com.sam.jifenbao;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PointsRecordActivity extends BaseHeaderActivity {
    private ListView recordListView;

    private static final String KEY_RECORD_NAME = "record_name";
    private static final String KEY_RECORD_COUNTS = "record_counts";
    private static final String KEY_RECORD_TIME = "record_time";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_points_record);
        findView();
        initView();
    }

    protected void findView(){
        recordListView = (ListView) findViewById(R.id.points_record_list);
    }

    protected void initView(){
        getHeaderView().setTitleText(R.string.points_record);
        List<Map<String, String>> data = new ArrayList<>();
        for(int i = 0; i < 20; i++){
            Map<String,String> map1 = new HashMap<>();
            map1.put(KEY_RECORD_NAME,"扫码积分"+i);
            map1.put(KEY_RECORD_COUNTS,"+"+(10+i));
            map1.put(KEY_RECORD_TIME,"2016/3/25 19:00");
            data.add(map1);
        }
        SimpleAdapter recordAdapter = new SimpleAdapter(this,data,R.layout.potins_record_list_item,
                new String[]{KEY_RECORD_NAME,KEY_RECORD_COUNTS,KEY_RECORD_TIME},
                new int[]{R.id.record_name,R.id.record_counts,R.id.record_time});
        recordListView.setAdapter(recordAdapter);

        recordListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                showShortToast("你点击了第"+position+"个记录");
            }
        });

        recordListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                showShortToast("你长按了第"+position+"个记录");
                return false;
            }
        });
    }


}
